package design_pattern.observer.demo_sendMsg;


public class Client {
    public static void main(String[] args) {
	HolderTypeOne h1 = new HolderTypeOne("h1");
	HolderTypeOne h2 = new HolderTypeOne("h2");
	HolderTypeOne h3 = new HolderTypeOne("h3");
	HolderTypeOne h4 = new HolderTypeOne("h4");
	
	HolderTypeTwo h5 = new HolderTypeTwo("h5");
	HolderTypeTwo h6 = new HolderTypeTwo("h6");
	HolderTypeTwo h7 = new HolderTypeTwo("h7");
	HolderTypeTwo h8 = new HolderTypeTwo("h8");
	
	MsgManager manager = new MsgManager();
	manager.register(h1).register(h2).register(h3).register(h4).register(h5).register(h6).register(h7).register(h8);
	Thread t = new Thread(new MsgChanger(manager));
	t.start();
	
    }
}
class MsgChanger implements Runnable{
    MsgManager manager;
    public MsgChanger(MsgManager m){
	manager=m;
    }
    @Override
    public void run() {
	for(int i = 0; i<5; i++){
	    manager.setMsg(new Msg("name: " + i));
	    try {
		Thread.sleep(2000);
	    } catch (InterruptedException e) {
		e.printStackTrace();
	    }
	}
	
    }
    
}